package xyz.labmem.common.property

import javafx.beans.property.Property
import javafx.beans.value.ObservableValue

class LabProperty<T>(private val dataP: Property<T>) {

    private val listenList = ArrayList<(T) -> Unit>()

    init {
        dataP.addListener { _, _, newValue ->
            listenList.forEach { it(newValue) }
        }
    }

    fun bind(observable: ObservableValue<out T>) {
        dataP.bind(observable)
    }

    fun addListen(listener: (T) -> Unit) {
        listenList.add(listener)
    }

    fun value(): T = dataP.value

    fun value(value: T) {
        dataP.value = value
    }

    fun property() = dataP

}